package com.example.membersteward.controller;

import com.example.membersteward.common.CommonResult;
import com.example.membersteward.entity.vo.RoleMenuVo;
import com.example.membersteward.service.RoleMenuService;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@RestController
@RequestMapping("/api")
public class RoleMenuController {
    @Resource
    RoleMenuService roleMenuService;

    @Resource
    ObjectMapper objectMapper;

    @GetMapping("/menuIds")
    public CommonResult getMenuIdsByRoleId(Long roleId) {
        return roleMenuService.getMenuIdsByRoleId(roleId);
    }

    @PostMapping("/assignPermission")
    public CommonResult assignPermission(@RequestBody RoleMenuVo roleMenuVo) {
        try {

            return roleMenuService.assignPermission(roleMenuVo.getRoleId(), roleMenuVo.getMenuIds());
        } catch (Exception e) {
            // 处理异常
            return CommonResult.error("解析用户信息失败");
        }
    }
}
